package com.shuoyue.ycgk.ui.questionbank.practice.mok;

import com.shuoyue.ycgk.entity.Option;
import com.shuoyue.ycgk.ui.questionbank.base.BaseSimpleFragment;

import java.util.ArrayList;
import java.util.List;

public class MokQuestionSimpleFragment extends BaseSimpleFragment {

    @Override
    protected void initView() {
        super.initView();
//        setQuestionAnswerIsRight();
    }

    @Override
    protected void initData() {
        isShowDK = false;
        super.initData();
        changeButtonTextAndTag("下一题", 3);
    }

    @Override
    public void showRightAnswers() {
//        super.showRightAnswers();
    }

    @Override
    protected void doClick(Option option) {
        questionSimple.setIsAnswerRight(3);//标记为已做答,未核对
        if (questionSimple.getQuestionType() == 1
        ) {
            //单选
            //改变选中状态
            if (!option.isSelect()) {//只有没有被选中的点击才改变
                //全部变成false
                for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                    o.setSelect(false);
                }
                //点击的变成true
                option.setSelect(!option.isSelect());
                //存储答案
                List<String> selectOption = new ArrayList<>();
                selectOption.add(option.getNo());
                questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);
            }
            //跳转下一题
            MokQuestionMateralFragment fragment = (MokQuestionMateralFragment) getParentFragment();
            if (fragment != null) {
                fragment.goNext();
            } else {
                activity.goNext();
            }
        } else if (questionSimple.getQuestionType() == 3) {
            //判断
            //改变选中状态
            if (!option.isSelect()) {//只有没有被选中的点击才改变
                //全部变成false
                for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                    o.setSelect(false);
                }
                //点击的变成true
                option.setSelect(!option.isSelect());
                //存储答案
                List<String> selectOption = new ArrayList<>();
                selectOption.add(option.getNo());
                questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);
            }
            //跳转下一题
            MokQuestionMateralFragment fragment = (MokQuestionMateralFragment) getParentFragment();
            if (fragment != null) {
                fragment.goNext();
            } else {
                activity.goNext();
            }
        } else if (questionSimple.getQuestionType() == 2) {
            //多选
            //点击后,改变选中状态
            option.setSelect(!option.isSelect());
            List<String> selectOption = new ArrayList<>();
            for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                if (o.isSelect()) {
                    selectOption.add(o.getNo());
                }
            }
            questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);

        }
        optionAdapter.notifyDataSetChanged();
        setButtonNextText();
    }

    @Override
    protected void controllClick() {
        //考试中只有下一题按钮
        if (totalCount == questionSimple.getNum()) {
            //最后一个
            activity.goNext();
        } else {
            MokQuestionMateralFragment fragment = (MokQuestionMateralFragment) getParentFragment();
            if (fragment != null) {
                fragment.goNext();
            } else {
                activity.goNext();
            }
        }
    }
}
